{% extends 'headbar.html' %}
{% load staticfiles %}
{% block main_content %}

    <link href="{% static 'js/kindeditor-4.1.10/themes/default/default.css' %}" rel="stylesheet">
    <script src="{% static 'js/kindeditor-4.1.10/kindeditor-all-min.js' %}"></script>
    <script src="{% static 'js/kindeditor-4.1.10/lang/zh-CN.js' %}"></script>

    <script>
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="content"]', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                //
                <!--去掉远程上传的功能-->
                allowImageRemote: false,
                width: '100%',
                height: '500px',
                uploadJson: '/admin/upload/kindeditor',
                afterBlur: function () {
                    this.sync();
                }
            });
        })

    </script>

    <div class="container">
        <div class="well">
            <div class="row">
                <div class="col-md-7 col-md-offset-2">
                     <div class="table-responsive">
                    <table class="table-condensed">
                        <tr>
                            {% for t in tags %}
                                <td>
                                    <h4><span
                                            class="label {% cycle 'label-info'  'label-warning' 'label-primary'  'label-success' 'label-danger' %}">{{ t }}
                                            </span>
                                    </h4>
                                </td>
                            {% endfor %}
                        </tr>
                    </table>
                </div>
                    <h3 id="tags" style="color: #2aabd2">{{ question.title }}</h3>
                    <br>
                    <h4 style="color:gray"> {{ question.desc }}</h4>
                </div>

            </div>
        </div>
        <hr>
        <div class="well">
            <div class="row">
                <div class="col-md-8 col-md-offset-1">
                    <textarea id="editor_id" name="content" class="form-control" rows="4">
                           {% autoescape off %}
                               {% for a in article %}
                                   {{ a.content }}
                               {% endfor %}
                           {% endautoescape %}
                    </textarea>
                </div>
                <div class="col-md-1 col-md-offset-1">
                    <button id='saveReply' type="button" class="btn btn-primary">保存提交</button>
                </div>
            </div>
        </div>
    </div>

    <script>
        $(document).ready(function () {
            $('#saveReply').click(function () {
                editor.sync();
{#                alert( $('#editor_id').val());#}
                $.ajax({
                    url: '{% url "answer" %}',
                    type: 'post',
                    dataType: 'text',
                    data: {
                        'user_id':{{ client.id }},
                        'question_id':{{ question.id }},
                        'article_content': $('#editor_id').val()
                    },
                    success: function (data) {
                        if (data == 'ok') {
                            $(window).attr('location', '/article/?qid={{ question.id }}');
                        }

                    },
                    error: function () {
                        alert('出现错误!')
                    }
                });

            });
        });

    </script>
{% endblock %}